package leetcode.code1750;

import leetcode.IDebug;

public class Solution implements IDebug {

	public int minimumLength(String s) {
		char[] cs = s.toCharArray();
		return this.minimumLength(cs, 0, cs.length - 1);
	}

	private int minimumLength(char[] cs, int L, int R) {
		if (L > R) {
			return 0;
		}
		if (L == R) {
			return 1;
		}
		if (cs[L] != cs[R]) {
			return R - L + 1;
		}
		int l = L;
		int r = R;
		while (l <= r && (l == L || cs[l] == cs[l - 1])) {
			l++;
		}
		while (l <= r && (r == R || cs[r] == cs[r + 1])) {
			r--;
		}
		return this.minimumLength(cs, l, r);
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
